package com.woniuxy.controller;

import com.woniuxy.entity.Drug;
import com.woniuxy.entity.DrugSum;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.ResponseResult;

import com.woniuxy.service.DrugService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.PublicKey;

@RestController
public class DrugController {

    @Resource
    DrugService drugService;

    @PostMapping("/du/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Drug>> selectDrugs(@PathVariable("pageIndex") int pageIndex,
                                                     @PathVariable("pageSize") int pageSize,
                                                     @RequestBody Drug drug){


        PageBean<Drug> drugPageBean=drugService.selectPage(drug,pageIndex,pageSize);

        ResponseResult<PageBean<Drug>> responseResult=new ResponseResult<>(200,"ok",drugPageBean);

        return responseResult;
    }

//    补货弹框库存数量
    @PostMapping("/gs")
    public ResponseResult<DrugSum> getSum(String repertoryName){

        DrugSum drugSum=drugService.getSum(repertoryName);

        ResponseResult<DrugSum> responseResults=new ResponseResult<>(200,"ok",drugSum);
        return responseResults;
    }

//    补货弹框确定补货，数据修改
    @PostMapping("/su")
    public ResponseResult sure(String repertoryName,Integer repertorySum,Integer drugSum){

        drugService.sureDrug(repertoryName,repertorySum,drugSum);

        return new ResponseResult(200,"ok",null);
    }

//    药品下架
    @PostMapping("/des")
    public ResponseResult deleteDrugs(String drugName){

        drugService.deleteDrug(drugName);

        return new ResponseResult(200,"ok",null);
    }
}
